package com.geralt.im.command.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.UUID;

import com.geralt.im.command.Command;
import com.geralt.im.tool.HtmlBuilder;
import com.geralt.im.tool.JsonTool;
import com.oocl.ita.winton.modle.NeedReplyMessage;
import com.oocl.ita.winton.modle.ServerInfo;
import com.oocl.ita.winton.weibodate.jms.MessageQueueConsumer;
import com.oocl.ita.winton.weibodate.jms.MessageQueueProducer;

public class StopCommand extends Command{

	@Override
	public String excete() {
		Properties props = new Properties();
		
		InputStream is = StopCommand.class.getClassLoader().getResourceAsStream("Queue.properties");
		try {
			props.load(is);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		String url = props.getProperty("url");
		String requsetQueue = props.getProperty("requsetQueue");
		String responseQueue = props.getProperty("responseQueue");
		MessageQueueProducer sender = new MessageQueueProducer(url,requsetQueue);
		MessageQueueConsumer consumer = new MessageQueueConsumer(url,responseQueue);
		sender.send(new NeedReplyMessage("STOP", UUID.randomUUID().toString()));
		sender.send(new NeedReplyMessage("INFO", UUID.randomUUID().toString()));
		sender.commit();
		String infoString = consumer.read();
		JsonTool jt = JsonTool.getInstance();
		ServerInfo info = (ServerInfo) jt.stringToObject(infoString, ServerInfo.class);
		System.out.println(infoString);
		String html = HtmlBuilder.buildHtml(info);
		sender.close_all();
		consumer.close_all();
		return html;
	}

}
